import { ArrayStark } from "./ArrayStark";
// 有效括号
function ValidParentheses(params: string): boolean {
  const stark = new ArrayStark();
  let flag = true;
  const map1 = ["(", "{", "["];
  const map2 = [")", "}", "]"];
  for (let i = 0; i < params.length; i++) {
    if (map1.includes(params[i])) {
      // 符合各种左括号入栈
      stark.push(params[i]);
      continue;
    }

    if (map2.includes(params[i])) {
      // 符合各种右括号， 抛出栈顶，且抛出的栈顶是有要求的
      if (stark.pop() !== map1[map2.indexOf(params[i])]) {
        flag = false;
        break;
      }
    }
  }
  // 发现左括号多了，也是有问题
  if (flag && !stark.isEmpty()) {
    flag = false;
  }
  return flag;
}

console.log(ValidParentheses("()[]"));
console.log(ValidParentheses("([])"));
console.log(ValidParentheses("([]"));
console.log(ValidParentheses("{((()))[]}"));
